<template>
	<view class="charts-box">
		<qiun-data-charts type="column" :opts="opts" :chart-data="chartData" background="none" />
	</view>
</template>

<script>
	export default {
		name: 'BarChart',
		props: {
			dataSource: {
				type: Array,
				default () {
					return []
				}
			}
		},
		watch: {
			'dataSource': {
				handler(dataSource) {
					let categories = []
					let seriesItem = {
						name: '出勤率',
						data: []
					}
					if (dataSource && dataSource.length) {
						dataSource.map(item => {
							categories.push(item.sleepStatusName)
							let percentage = Number(item.percentage)
							seriesItem.data.push(percentage)
						})
					}
					this.chartData.categories = categories
					this.chartData.series[0] = seriesItem
					console.log(this.chartData)
				},
				immediate: true
			}
		},
		data() {
			return {
				chartData: {
					"categories": [],
					"series": [{
						"name": "目标值",
						"data": []
					}]
				},
				opts: {
					"type": "column",
					"canvas2d": false,
					"background": "none",
					"animation": true,
					"timing": "easeOut",
					"duration": 1000,
					"padding": [0, 0, 0, 0],
					"rotate": false,
					"errorReload": true,
					"fontSize": 13,
					"fontColor": "#333",
					"enableScroll": true,
					"touchMoveLimit": 60,
					"enableMarkLine": false,
					"dataLabel": true,
					"dataPointShape": true,
					"dataPointShapeType": "solid",
					"tapLegend": true,
					"xAxis": {
						"disabled": false,
						"axisLine": true,
						"axisLineColor": "#CCCCCC",
						"calibration": false,
						"fontColor": "#333",
						"fontSize": 13,
						"rotateLabel": false,
						"itemCount": 7,
						"boundaryGap": "center",
						"disableGrid": true,
						"gridColor": "#CCCCCC",
						"gridType": "solid",
						"dashLength": 4,
						"gridEval": 1,
						"scrollShow": false,
						"scrollAlign": "left",
						"scrollColor": "#A6A6A6",
						"scrollBackgroundColor": "#EFEBEF",
						"format": ""
					},
					"yAxis": {
						"disabled": false,
						"disableGrid": true,
						"splitNumber": 5,
						"gridType": "solid",
						"dashLength": 8,
						"gridColor": "#CCCCCC",
						"padding": 30,
						"showTitle": false,
						"data": []
					},
					"legend": {
						"show": false,
					},
					"extra": {
						"column": {
							"type": "group",
							"width": 30,
							"seriesGap": 2,
							"categoryGap": 3,
							"barBorderCircle": false,
							"linearType": "none",
							"linearOpacity": 1,
							"colorStop": 0,
							"meterBorder": 1,
							"meterFillColor": "#FFFFFF",
							"activeBgColor": "#000000",
							"activeBgOpacity": 0.08,
							"meterBorde": 1
						},
						"tooltip": {
							"showBox": true,
							"showArrow": true,
							"showCategory": false,
							"borderWidth": 0,
							"borderRadius": 0,
							"borderColor": "#000000",
							"borderOpacity": 0.7,
							"bgColor": "#000000",
							"bgOpacity": 0.7,
							"gridType": "solid",
							"dashLength": 4,
							"gridColor": "#CCCCCC",
							"fontColor": "#FFFFFF",
							"splitLine": true,
							"horizentalLine": false,
							"xAxisLabel": false,
							"yAxisLabel": false,
							"labelBgColor": "#FFFFFF",
							"labelBgOpacity": 0.7,
							"labelFontColor": "#666666"
						},
						"markLine": {
							"type": "solid",
							"dashLength": 4,
							"data": []
						}
					}
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.charts-box {
		width: 100%;
		height: 360rpx;
	}
</style>r
